﻿using System.Collections;

namespace Simple.Services;

public class QHSEOverLappingOrganizationTreeNodeModel : QHSEOverLappingOrganizationModel, ITreeNode
{
    /// <summary>
    /// 主键
    /// </summary>
    public new string? Id { get; set; }

    /// <summary>
    /// 父级Id
    /// </summary>
    public string? ParentId { get; set; }

    public List<QHSEOverLappingOrganizationTreeNodeModel> Children { get; set; } = new List<QHSEOverLappingOrganizationTreeNodeModel>();

    public void SetChildren(IList children)
    {
        var nodes = children as List<QHSEOverLappingOrganizationTreeNodeModel>;
        Children = nodes != null ? nodes : new List<QHSEOverLappingOrganizationTreeNodeModel>();
    }

    public static TreeBuilder<QHSEOverLappingOrganizationTreeNodeModel> CreateBuilder(List<QHSEOverLappingOrganizationTreeNodeModel> nodes, string rootId)
    {
        return new TreeBuilder<QHSEOverLappingOrganizationTreeNodeModel>(nodes, rootId);
    }

    public override void ConfigureMapper(Profile profile)
    {
        profile.CreateMap<QHSESysOverLappingOrganization, QHSEOverLappingOrganizationTreeNodeModel>()
            .ForMember(d => d.Id, options => options.MapFrom(s => s.OrganizationId));

        profile.CreateMap<QHSEOverLappingOrganizationTreeNodeModel, QHSESysOverLappingOrganization>()
            .ForMember(d => d.OrganizationId, options => options.MapFrom(s => s.Id));
    }
}
